package com.libbase.kotlin.viewmodel

import android.arch.lifecycle.LifecycleOwner
import android.arch.lifecycle.Observer
import com.base.kotlin.mvvm.BaseVmPresenter
import com.base.kotlin.mvvm.IView
import com.libbase.kotlin.presenter.NyqfContract

class NyqfVmPresenter : BaseVmPresenter<IView.DefaultView>(), NyqfContract.Presenter {

    companion object {
        const val ACTION_TITLE = 1
    }

    private var nyqfViewModel: NyqfViewModel? = null

    override fun onCreate() {
        mView?.let {
            nyqfViewModel = getViewModel(it.getOwer(), NyqfViewModel::class.java)
        }
    }

    override fun getTitles() {
        mView?.let {
            it.showLoading()
            nyqfViewModel?.liveData?.observe(it.getOwer() as LifecycleOwner, Observer { data ->
                it.hideLoading()
                it.onDefaultSuccess(ACTION_TITLE, data)
            })
            nyqfViewModel?.getTitles()?.also { disposable ->
                mDisposables.add(disposable)
            }
        }
    }
}
